//
//  THJPartPayVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/8/11.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJPartPayVC.h"

@interface THJPartPayVC ()

@end

@implementation THJPartPayVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"分批支付"];
    }else{
        [self setNavBarWithTitle:@"分批支付"];
    }
    [self getData];
    self.tf.secureTextEntry = YES;
    // Do any additional setup after loading the view from its nib.
}
-(void)getData{
    [self SVHUDShow];
    NSString * itemid = [RSA encryptString:self.itemid publicKey:RSA_PubKey];
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=buyer_part_order" parameters:@{@"itemid":itemid,@"type":@"ios"} callback:^(NSDictionary *  receiveData, NSError *error) {
        NSLog(@"分批支付--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
            self.lab1.text = [RSA decryptString:receiveData[@"data"][@"yMoney"] publicKey:RSA_PubKey];
            self.lab2.text = [RSA decryptString:receiveData[@"data"][@"buyer_accnm"] publicKey:RSA_PubKey];
            self.lab3.text = [RSA decryptString:receiveData[@"data"][@"seller_accnm"] publicKey:RSA_PubKey];
            self.lab4.text = [RSA decryptString:receiveData[@"data"][@"seller_accno"] publicKey:RSA_PubKey];
            self.lab5.text = [RSA decryptString:receiveData[@"data"][@"amount"] publicKey:RSA_PubKey];
            self.lab7.text = [RSA decryptString:receiveData[@"data"][@"yes_money"] publicKey:RSA_PubKey];
            self.lab8.text = [RSA decryptString:receiveData[@"data"][@"no_money"] publicKey:RSA_PubKey];
        }else{
            [self HUDShowMsg:@"获取信息失败" AfterDelayDimiss:1];
        }
        
    }];
}
- (IBAction)sureBtnAction:(id)sender {
    if(self.tf1.text.length == 0){
        [self HUDShowMsg:@"请输入支付金额" AfterDelayDimiss:1];
        return;
    }else if(self.tf.text.length == 0){
        [self HUDShowMsg:@"请输入支付密码" AfterDelayDimiss:1];
        return;
    }else if([self.tf1.text floatValue]>[self.lab1.text floatValue]){
        [self HUDShowMsg:@"支付金额不能大于可用余额" AfterDelayDimiss:1];
        return;
        return;
    }else if([self.tf1.text floatValue]>[self.lab8.text floatValue]){
        [self HUDShowMsg:@"支付金额不能大于未付金额" AfterDelayDimiss:1];
        return;
        return;
    }else if([self.tf1.text floatValue]>[self.lab5.text floatValue]){
        [self HUDShowMsg:@"支付金额不能大于订单总额" AfterDelayDimiss:1];
        return;
        return;
    }else{
        [self SVHUDShow];
        NSString * mobile = [RSA encryptString:[THJTools getMobile] publicKey:RSA_PubKey];
        NSString * itemid = [RSA encryptString:self.itemid publicKey:RSA_PubKey];
        NSString * pwd = [RSA encryptString:self.tf.text publicKey:RSA_PubKey];
        NSString * money = [RSA encryptString:self.tf1.text publicKey:RSA_PubKey];
        NSDictionary * dic = @{
                               @"type":@"ios",
                               @"mobile":mobile,
                               @"itemid":itemid,
                               @"pwd":pwd,
                               @"money":money
                               };
        [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=buyer_part_gotopay" parameters:dic callback:^(NSDictionary *  receiveData, NSError *error) {
            NSLog(@"分批支付--%@--%@",receiveData,[RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey]);
            [self SVHUDHiden];
            if([receiveData[@"status"] isEqual:@"success"]){
                [self HUDShowMsg:@"支付成功" AfterDelayDimiss:1];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"paySuccess" object:nil userInfo:nil];
                [self performSelector:@selector(popAction) withObject:nil afterDelay:1];
                [self getData];
            }else{
                [self HUDShowMsg:[RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey] AfterDelayDimiss:1];
            }
        }];
    }
}
-(void)popAction{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
